<!DOCTYPE html>
<!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  ~ Copyright © 2013-2016 The Nxt Core Developers.                            ~
  ~ Copyright © 2016-2017 Jelurida IP B.V.                                    ~
  ~                                                                           ~
  ~ See the LICENSE.txt file at the top-level directory of this distribution  ~
  ~ for licensing information.                                                ~
  ~                                                                           ~
  ~ Unless otherwise agreed in a custom licensing agreement with Jelurida B.V.,
  ~ no part of the Nxt software, including this file, may be copied, modified,~
  ~ propagated, or distributed except according to the terms contained in the ~
  ~ LICENSE.txt file.                                                         ~
  ~                                                                           ~
  ~ Removal or modification of this copyright notice is prohibited.           ~
  ~                                                                           ~
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->

<html>
    <head>
        <meta charset="UTF-8">
        <style type="text/css">
            body {background-color: #E0E0E0; color: #000; font-family: Tahoma; font-size: 10pt; margin: 0; padding: 10px;}
            table {border-collapse: collapse; width: 100%;}
            td {height: 20px; line-height: 20px; padding: 0;}
            .disabledAnnouncedAddress {background-image: url(); width: 20px;}
            .enabledAnnouncedAddress {background-image: url(); width: 20px;}
            .remove {background-image: url(); cursor: pointer; width: 20px;}
            .text {cursor: default; padding: 0 10px 0 5px; white-space: nowrap;}
            .wellKnown {background-image: url(); width: 20px;}
            .software {background-image: url(); width: 20px;}
        </style>
        <script type="text/javascript">
            function addPeer(peer) {
                if (document.getElementById("peer" + peer.index) != null) return;
                var peers = document.getElementById("peers"), row = peers.insertRow(peers.rows.length), element;
                row.id = "peer" + peer.index;
                element = row.insertCell(0);
                element.className = "text";
                element.title = peer.address;
                element.innerHTML = peer.address;
                element = row.insertCell(1);
                if (peer.wellKnown) {
                    element.className = "wellKnown";
                    element.title = "Well-known address";
                } else {
                    if (peer.announcedAddress.length > 1) {
                        element.className = "enabledAnnouncedAddress";
                    } else {
                        element.className = "disabledAnnouncedAddress";
                    }
                    element.title = "Announced address";
                }
                element = row.insertCell(2);
                element.className = "text";
                element.title = peer.announcedAddress;
                element.textContent = peer.announcedAddress;
                element = row.insertCell(3);
                element.className = "software";
                element.title = "Software";
                element = row.insertCell(4);
                element.className = "text";
                element.title = "Application (version)";
                element.textContent = peer.software;
                element = row.insertCell(5);
                element.className = "remove";
                element.title = "Remove completely";
                element.onclick = function() {
                    requestPeerRemoving(peer.index);
                };
                element = parent.document.getElementById("knownPeersCounter");
                element.innerHTML = parseInt(element.innerHTML) + 1;
            }

            function addPeers(peers) {
                var i;
                for (i = 0; i < peers.length; i++) {
                    addPeer(peers[i]);
                }
            }

            function removePeer(peer) {if (document.getElementById("peer" + peer.index)==null)return;
                document.getElementById("peers").deleteRow(document.getElementById("peer" + peer.index).rowIndex);
                var element = parent.document.getElementById("knownPeersCounter");
                element.innerHTML = parseInt(element.innerHTML) - 1;
            }

            function removePeers(peers) {
                var i;
                for (i = 0; i < peers.length; i++) {
                    removePeer(peers[i]);
                }
            }

            function requestPeerRemoving(index) {
                parent.sendRequest("removeKnownPeer&peer=" + index);
            }
        </script>
    </head>
    <body>
        <table id="peers"></table>
    </body>
</html>